/*
 @brief Hardware specific configuration for Soft IIC. 
 
 Stone at home, Feb 2023
*/


#ifndef SOFTIIC_HARDWARE_H__
#define SOFTIIC_HARDWARE_H__

#include <stm32f10x.h>
#include <stm32f10x_conf.h>


/* ------------------------------------------------------
    The follwoing definitions try to abstract a IIC layer, so as to
    minimize the necessary changes when hardware is changed.
   ------------------------------------------------------ */



// ===== Definition of logic level =====
#define SoftIIC_LogicHIGH 1
#define SoftIIC_LogicLOW  0


typedef struct {
    uint32_t RCC_SCL;   // RCC_APB2Periph_GPIOx
    uint32_t RCC_SDA;
    GPIO_TypeDef *port_SCL;
    uint16_t pin_SCL;
    GPIO_TypeDef *port_SDA;
    uint16_t pin_SDA;
} SoftIIC_HardwareTypeDef;


void SoftIIC_Hardware_Init(const SoftIIC_HardwareTypeDef * const hardware);

// These functions expect parameter with type of SoftIIC_HardwareTypeDef *
#define SoftIIC_SCL_Low(hw)  GPIO_ResetBits((hw)->port_SCL, (hw)->pin_SCL)
#define SoftIIC_SCL_High(hw) GPIO_SetBits((hw)->port_SCL, (hw)->pin_SCL)
#define SoftIIC_SDA_Low(hw)  GPIO_ResetBits((hw)->port_SDA, (hw)->pin_SDA)
#define SoftIIC_SDA_High(hw) GPIO_SetBits((hw)->port_SDA, (hw)->pin_SDA)
#define SoftIIC_SDA_Read(hw) GPIO_ReadInputDataBit((hw)->port_SDA, (hw)->pin_SDA)


#endif  // SOFTIIC_HARDWARE_H__
